package com.amit.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginServlet  extends HttpServlet{
	
	
	public LoginServlet()
	{
		System.out.println("defaultconstructor");
	}

	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException 
			{
		
		String unm=request.getParameter("uname");
		String pwd=request.getParameter("pswd");
		String lang=request.getParameter("language");
		
		request.getSession().setAttribute("LANGUAGE",lang);
		if(unm==null||unm.trim().length()==0||pwd==null||pwd.trim().length()==0)
		{
			request.setAttribute("REQUIRED", "");
			request.getRequestDispatcher("index.jsp").forward(request, response);
			
			return;
		}
		
		if(unm.equals(pwd))
		{
			request.setAttribute("UNM", unm);
			request.getRequestDispatcher("/WEB-INF/home.jsp").forward(request, response);
		}
		else
		{
			request.setAttribute("ERROR", "");
			request.getRequestDispatcher("index.jsp").forward(request, response);
		}
		
	}
}
